﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using log4net;

namespace Entangle
{
    /// <summary>
    /// Interaction logic for Pair.xaml
    /// </summary>
    public partial class Pair : Window
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Pair));

        public Pair()
        {
            InitializeComponent();
        }
        private void btnSynchronize_Click(object sender, RoutedEventArgs e)
        {
            log.Info("Pairing begin.");
            try
            {
                log.Debug("Obtaining synch service for '" + txtSynchServerURL.Text + "' server.");
                SynchService sync = new SynchService(txtSynchServerURL.Text);

                log.Debug("Initiating synch with key:" + txtSynchKey.Text);
                sync.Synch2(txtSynchKey.Text);
                log.Info("Pairing succesful. Saving synch server address.");
                Configuration.SynchServer = txtSynchServerURL.Text;
                this.DialogResult = true;
                Close();
            }
            catch (Exception ex)
            {
                log.Error("Exception occured while pairing.", ex);
                MessageBox.Show("Error occured:"+ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
